﻿ #region Disclaimer/Info
 
 /////////////////////////////////////////////////////////////////////////////////////////////////
 //
 //   File:		Category.Builder.cs
 //   Website:		http://dexterblogengine.com/
 //   Authors:		http://dexterblogengine.com/About.ashx
 //   Rev:		1
 //   Created:		19/01/2011
 //   Last edit:		19/01/2011
 //   License:		GNU Library General Public License (LGPL)
 //   File:            Category.Builder.cs
 //   For updated news and information please visit http://dexterblogengine.com/
 //   Dexter is hosted to Codeplex at http://dexterblogengine.codeplex.com
 //   For any question contact info@dexterblogengine.com
 //
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
 #endregion
 
using System;
using Topics.Radical.Validation;

namespace Dexter.Domain.Model {
	public partial class Category {
		
		/// <summary>
		/// Creates a new instance of <see cref="Category"/>.
		/// </summary>
		/// <param name="name">The name of the <see cref="Category"/>.</param>
		/// <param name="parent">The parent <see cref="Category"/>.</param>
		/// <returns>
		/// A new instance of <see cref="Category"/>
		/// </returns>
		/// <exception cref="ArgumentNullException"> If <paramref name="name"/> is <c>null</c> or <c>empty</c>.</exception>
		/// <exception cref="ArgumentOutOfRangeException">Will be throw if the the parent <see cref="Category"/> is not <c>null</c> but the property id of its will be lesser then 1.</exception>
		public static Category CreateNewCategory ( string name , Category parent ) {
			Ensure.That ( name )
				.Named ( "name" )
				.WithPreview ( ( v , e ) => Logger.Warn ( v.GetFullErrorMessage ( ) , e ) )
				.IsNotNullNorEmpty ( );

			if ( parent != null ) {
				Ensure.That ( parent.Id )
					.Named ( "parent.Id" )
					.WithPreview ( ( v , e ) => Logger.Warn ( v.GetFullErrorMessage ( ) , e ) )
					.IsGreaterThen ( 0 )
					.WithMessage ( "The parent category key is invalid." );
			}

			return new Category ( name , parent );
		}
	}
}
